import request from '../index';

/**
 * security 一块的
 */
// security
// ipfilter
export async function getSecurityInfo() {
    return request({
        url: '/api/security/ip/filter',
        method: 'get'
    });
}

export function setIpEnabled(enabled){
    return request({
        url: '/api/security/ip/enable',
        method: 'post',
        data: {
            enabled 
        }
    });
}

export function setIpFilterEnabled(enabled){
    return request({
        url: '/api/security/ip/enable',
        method: 'post',
        data: {
            enabled 
        }
    });
}

// ipfilter 名单列表
export async function getIpList() {
    return request({
        url: '/api/security/ip/rules',
        method: 'get'
    });
}
// 规则（黑/白名单）
export async function setIpPolicy(params) {
    return request({
        url: '/api/security/ip/polilcy',
        method: 'post',
        data: params
    });
}

// 新增IP
export async function addIpFilter(params) {
    return request({
        url: '/api/security/ip/add',
        method: 'post',
        data: params
    });
}
// 编辑IP
export async function editIpFilter(params) {
    return request({
        url: '/api/security/ip/update',
        method: 'post',
        data: params
    });
}
// 删除IP
export async function delIpFilter(params) {
    return request({
        url: '/api/security/ip/delete',
        method: 'post',
        data: params
    });
}

// accessControl

export function setAccessControlEnabled(enabled){
    return request({
        url: '/api/security/accesscontrol/enable',
        method: 'post',
        data: {
            enabled 
        }
    });
}

// get
export async function getAccessControlInfo() {
    return request({
        url: '/api/security/accesscontrol',
        method: 'get'
    });
}
// add
/**
 * 添加访问控制规则
 * @param {Object} data - 规则数据
 * @param {string} data.Aias - 规则名称
 * @param {string} data.SourceIP - 源IP
 * @param {string} data.DestIP - 目标IP
 * @param {string} data.SourcePort - 源端口
 * @param {string} data.DestPort - 目标端口
 * @param {string} data.Policy - 策略(Accept/Reject)
 * @param {string} data.Protocol - 协议类型
 * @param {string} data.IpType - IP类型(4/6)
 * @param {string} data.Order - 规则顺序
 * @returns {Promise} 
 */
export function addAccessControl(params) {
    return request({
        url: '/api/security/accesscontrol/add',
        method: 'post',
        data: params
    });
}

// update
export async function updateAccessControl(params) {
    return request({
        url: '/api/security/accesscontrol/update',
        method: 'post',
        data: params
    });
}
// del
export async function delAccessControl(id) {
    return request({
        url: '/api/security/accesscontrol/delete',
        method: 'post',
        data:{id}
    });
}

// mac
// get
export async function getMacRules() {
    return request({
        url: '/api/security/mac/rules',
        method: 'get'
    });
}

export async function setMacInfo(params) {
    return request({
        url: '/api/security/mac/update',
        method: 'post',
        data: params
    });
}
export async function addMacInfo(params) {
    return request({
        url: '/api/security/mac/add',
        method: 'post',
        data: params
    });
}
export async function delMacInfo(params) {
    return request({
        url: '/api/security/mac/delete',
        method: 'post',
        data: params
    });
}
